Lab Exam #1

Please do your work inside this page and return this page in a zip file to your instructor via email.

1. Define a global variable called studentName and assign your name to the field.

2. Define a global variable called courseName and assign the course name "WDV221 Intro to Javascript" to the variable.

3. Create a runtime script that will display studentName as an H1 element and the courseName as an H2 element.

4. Create a function called displayCourseName that will use an alert() to display the courseName variable. Use an onclick event handler on this paragraph to call the function. The message should be 'Course Name: theName'. Use the courseName variable for theName.

Item Price:

Number Purchased:

Sales Tax: (Please enter .06 for 6%, .10 for a 10% sales tax, etc.)

Total Price Including Sales Tax:

1. Change one of the submit buttons to "Calculate Price". Apply an onclick event handler to call the computeCost function.

2. Change the other button to a reset button to reset the form.

5. Given the form create a function called computeCost. The computeCost function should do the following things:

  1. Create a local variable called unitPrice. Take the information from the Item Price textfield and place it in the variable.
  2. Create a local variable called purchaseNumber. Take the information from the Number Purchased field and place it in the variable.
  3. Create a local variable called total Price.
  4. The function should multiply unitPrice * purchaseNumber and assign it to totalPrice.
  5. Display the value of totalPrice in the textfield next to Total Price on the form.
  6. Replace the yourName with the value of the studentName variable. Hint: Use .innerHTML.

Note: Even if you do not complete the function make sure it runs without breaking. Partial credit will be given for any work that runs corectly.

Extra Credit:

Add a field to the form called Sales Tax. Calculate the Sales tax on the Total Price and display it on the form in the Sales Tax field. Add the Sales Tax to the Total Price and change the Total Price field to reflect the new amount.